<?php
require_once ("settings.php");

class DBConnection {
	private $m_mysqli = NULL;

	public function Connect() {
		$password = "";
		$this -> m_mysqli = new mysqli(settings::DBhost, settings::DBroot, settings::DBPassword, settings::DBdatabase);

		//utf 8
		$this -> m_mysqli -> set_charset("utf8");

		//kollar kopplingen till  databasen.
		if ($this -> m_mysqli -> connect_errno) {
			echo "Connect failed: $this->m_mysqli->connect_error";
			return false;
		} else {

			echo "har kontakt med databasen</br>";

		}
		return true;
	}

	public function Prepare($sql) {
		$stmt = $this -> m_mysqli -> prepare($sql);
		if ($stmt === FALSE) {
			echo "prepare of '$sql' failed " . $this -> m_mysqli -> error;
			return false;
		}
		return $stmt;
	}

	public function Close() {
		echo "Close Connection";
		$this -> m_mysqli -> close();
	}

	public function error() {

		$wrong = "funktionen som heter error som ligger i db_c";

		return $wrong;
	}

}
